package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.model.entity.ReserveRegister;
import com.qf.model.vo.ReserveRegisterVO;
import com.qf.service.ReserveRegisterService;
import com.qf.util.R;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.Map;

/**
 * (ReserveRegister)表控制层
 *
 * @author makejava
 * @since 2024-05-05 14:41:49
 */
@RestController
@RequestMapping("/api/register")
public class ReserveRegisterController {
    /**
     * 服务对象
     */
    @Autowired
    private ReserveRegisterService reserveRegisterService;

    /**
     * 分页查询
     *
     * @return 查询结果
     */
    @GetMapping("/list")
    public R queryByPage(Long pageNum) {
        return R.ok(this.reserveRegisterService.queryByPage(pageNum));

    }

    @RequestMapping("/list/page")
    public R selectRegisterWithPatientByCondition(@RequestParam Map<String, Object> map) {
        int pageNum = Integer.parseInt((String) map.get("pageNum"));
        int pageSize = Integer.parseInt((String) map.get("pageSize"));

        PageHelper.startPage(pageNum,pageSize);

        List<ReserveRegisterVO> list = reserveRegisterService.selectRegisterWithPatientByCondition(map);
        if (list != null && !list.isEmpty()) {
            PageInfo<ReserveRegisterVO> pageInfo = new PageInfo<>(list);
            return R.ok(pageInfo);
        }
        return R.fail();
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    public R queryById(@PathVariable("id") Long id) {
        return R.ok(this.reserveRegisterService.queryById(id));
    }

    /**
     * 新增数据
     *
     * @param reserveRegister 实体
     * @return 新增结果
     */
    @PostMapping("/save")
    public R add(@RequestBody ReserveRegister reserveRegister) {
        return R.ok(this.reserveRegisterService.insert(reserveRegister));
    }

    /**
     * 编辑数据
     *
     * @param reserveRegister 实体
     * @return 编辑结果
     */
    @PostMapping("/edit")
    public R edit(@RequestBody ReserveRegister reserveRegister) {
        return R.ok(this.reserveRegisterService.update(reserveRegister));
    }

    /**
     * 删除数据
     *
     * @param id 主键
     * @return 删除是否成功
     */
    @GetMapping("/del")
    public R deleteById(Long id) {
        return R.ok(this.reserveRegisterService.deleteById(id));
    }

}

